package com.itheima.interface3;

//  定义第二套实现类，实现接口：实现打印全班学生信息（包括男女人数）、打印平均分（去掉最高分和最低分）
public class ClassDataImpl2 implements ClassData {

    private Student[] students;

    public ClassDataImpl2(Student[] students) {
        this.students = students;
    }

    @Override
    public void printAllStudentInfo() {
        System.out.println("全班学生信息如下：");
        int maleCount = 0;
        for (Student student : students) {
            System.out.println(student);
            if (student.getGender().equals("男")) {
                maleCount++;
            }
        }
        System.out.println("男生人数：" + maleCount);
        System.out.println("女生人数：" + (students.length - maleCount));

    }

    //打印平均分（去掉最高分和最低分）
    @Override
    public void printAverageScore() {
        double sum = 0;
        double max = students[0].getScore();
        double min = students[0].getScore();
        for (Student student : students) {

            double score = student.getScore();

            sum += score;

            if (score > max) {
                max = score;
            }

            if (score < min) {
                min = score;
            }
        }
        System.out.println("最高分：" + max);
        System.out.println("最低分：" + min);
        System.out.println("去掉最高分和最低分后的平均分：" + (sum - max - min) / (students.length - 2));
    }
}
